# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=leocad
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=23.03
_libver=23.06
pkgrel=1
pkgdesc='A CAD program for creating virtual LEGO models (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://leocad.org'
msys2_repository_url='https://github.com/leozide/leocad'
msys2_references=(
  "cpe: cpe:/a:leocad:leocad"
)
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5-tools: Designer plugin")
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "${msys2_repository_url}/releases/download/v${pkgver}/Library-${_libver}.zip"
        '0001-leocad-23.03-fix-install.patch')
sha256sums=('69a45c60898ed07d8cf7e714442b201b0da3adc073287170eb6f46901e4604ce'
            'ef29c1e0fc989c9e9894072f43ae0030a5274c0cdcc831bc6c206bbe059f449b'
            '850e7fb4f1d43f6d865284e7338628c5d29aa20d03b99f71c2fb4ac356ad3fba')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  apply_patch_with_msg \
    0001-leocad-23.03-fix-install.patch
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/qmake.exe \
    INSTALL_PREFIX=${MINGW_PREFIX} \
    DISABLE_UPDATE_CHECK=1 \
    ../${_realname}-${pkgver}/${_realname}.pro

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install

  install -Dm644 "${srcdir}/library.bin" -t "${pkgdir}${MINGW_PREFIX}/share/leocad"
}

# vim:set ts=2 sw=2 et:
